//-----------头文件区----------
#include "sqlite3.h"
#include <gtk/gtk.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
//------------------------------




//-------------全局变量区----------------
sqlite3 *db = NULL;
GtkWidget* window_main;
GtkWidget* window_rk;
GtkWidget* window_rk;
GtkWidget* window_yh;
GtkWidget* yh_id;
GtkWidget* yh_passwd;
GtkWidget* yh_yzm;
GtkWidget* yh_ye;
GtkWidget* yh_changguan;
GtkWidget* label_user_passwd;
GtkWidget* label_user_changguan;
GtkWidget* label_user_xm;
GtkWidget* label_user_ye;
GtkWidget* label_yh_yzms;
GtkWidget* window_yh_cd;
GtkWidget* window_yh_cz;
GtkWidget* window_yh_cx;
GtkWidget* yh_cz_yue;
GtkWidget* yh_cz_jine;
GtkWidget* window_yh_xg;
GtkWidget*  label_user_xg_xm_new;
GtkWidget* label_user_xg_passwd_new;
GtkWidget* label_user_xg_xm;
GtkWidget* label_user_xg_passwd;
GtkWidget* label_user_xg_id;
GtkWidget* window_yh_yu;
GtkWidget* entry_user_xzkcm;
GtkWidget* label_gly_yzms;
GtkWidget* window_gly_cd;
GtkWidget* window_gly;
GtkWidget* gly_yzm;
GtkWidget* gly_passwd;
GtkWidget* gly_id;
GtkWidget* label_gly_cx_id;
GtkWidget* window_gly_cx;
GtkWidget* window_gly_xg;
GtkWidget* label_gly_sc_id;

GtkWidget* window_gly_sc;
GtkWidget* window_gly_zj;
GtkWidget* label_gly_zj_id;
GtkWidget* label_gly_zj_mm;
GtkWidget* gly_gly_cx_id;
GtkWidget* gly_user_ye;
GtkWidget* gly_user_xm;
GtkWidget* gly_user_passwd;
GtkWidget* gly_user_changguan;

GtkWidget* gly_user_xg_id;
GtkWidget* gly_user_xg_passwd;
GtkWidget* gly_user_xg_xm;

//-----------------------------------------



//-------------------回调函数区------------

//window_main_to_rk 刚开始的界面跳转到进入界面
void window_main_to_rk(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_rk);  //window_rk就是进入界面定义的全局变量
	//隐藏当前的页面
	gtk_widget_hide_all(window_main);
	
}

//从进入的界面跳到用户界面
void window_rk_to_yh(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_rk);
}

//从用户界面返回进入界面
void window_yh_to_rk(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_rk);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh);
}


//用户登录界面刷新
void window_yh_sx(GtkButton* button,gpointer user_data)
{
	//清空界面
	//设置y_的内容都为空字符串
	gtk_entry_set_text(GTK_ENTRY(yh_id),"");
	gtk_entry_set_text(GTK_ENTRY(yh_passwd),"");
	gtk_entry_set_text(GTK_ENTRY(yh_yzm),"");
	//生成
	char haha[4] = "";
	srand(time(NULL));
	int i = 0;
	for (i = 0; i < 4; ++i)
	{
		if(rand()%2 == 0)
			haha[i] = rand()%26+'a';
		else
			haha[i] = rand()%10+'0';
	}

	//设置上去
	char yzm[200] = "";
	sprintf(yzm,"<span foreground='red'  font_desc='25'>%s</span>",haha);
	gtk_label_set_markup(GTK_LABEL(label_yh_yzms),yzm);

	
}

//从用户菜单界面到用户登录界面
void yh_cd_to_yh_dl(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cd);
}

// 从用户菜单跳转到用户充值
void yh_cd_to_yh_cz(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cz);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cd);
}

//从用户充值界面到用户菜单界面
void yh_cz_to_cd(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cd);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cz);
}


//从用户查询界面到用户菜单界面
void window_cx_to_cd(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cd);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cx);
}

//从用户修改到用户菜单
void window_xg_to_cd(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cd);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_xg);
}

//从用户菜单界面到用户修改界面
void yh_cd_to_yh_xg(GtkButton* button,gpointer user_data)
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_xg);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cd);
}

//从用户菜单跳转到预约功能
void yh_cd_to_yh_yu()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_yu);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cd);
}

void window_yu_to_cd()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cd);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_yu);
}

//预约上获取第几场馆的（获取按钮上的内容）
void user_do_yu(GtkButton* button,gpointer user_data)
{

	const char* kc = gtk_button_get_label(button);
	gtk_entry_set_text(GTK_ENTRY(entry_user_xzkcm),kc);
}


//管理员登录界面到入口界面
void window_gly_to_rk()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_rk);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly);
	
}

//从入口界面跳转到管理员登录界面
void window_rk_to_gly()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly);
	//隐藏当前的页面
	gtk_widget_hide_all(window_rk);
}

//管理员查询用户界面调转到管理员菜单界面
void window_gly_cx_to_cd()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cd);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cx);
}

//从管理员菜单界面转到管理员查询用户信息界面
void gly_cd_to_gly_cx()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cx);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}

//从管理员的修改用户信息界面的跳转到管理员的菜单界面
void window_gly_xg_to_gly_cd()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cd);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_xg);
}

//从管理员的菜单界面跳转到管理员的修改用户信息界面
void gly_cd_to_gly_xg()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_xg);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}

//管理员删除界面跳转到管理员菜单
void window_gly_sc_to_gly_cd()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cd);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_sc);
}

//管理员菜单界面到管理员删除界面
void gly_cd_to_gly_sc()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_sc);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}

//管理员增加用户界面跳转到菜单界面
void window_gly_zj_to_gly_cd()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cd);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_zj);
}

//管理员菜单界面到管理员增加界面
void gly_cd_to_gly_zj()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_zj);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}
//从管理员菜单到管理员登录界面
void gly_cd_to_gly()
{
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly);
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}

//-----------------------------------------------------------




//---------------含有数据库的回调函数-----------------------
// 用户界面注册函数
void window_yh_zc(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(yh_passwd));
	const char * yzm = gtk_entry_get_text(GTK_ENTRY(yh_yzm));
	const char * yzm_old = gtk_label_get_text(GTK_LABEL(label_yh_yzms));
	if (0!=strcmp(yzm,yzm_old))//如果验证码错误
	{
		gtk_entry_set_text(GTK_ENTRY(yh_yzm),"验证码错误");
		sqlite3_close(db);
		return;
	}

	// 根据数据组合一个sql语句
	char sql1[100] = "";
	sprintf(sql1,"select * from user where xm = \'%s\';",id);
	// 看sql语句是读还是写
	char ** table = NULL;
	char * errmsg = NULL;
	int r = 0,c = 0;
	// 如果是读就用sqlite3_get_table
	sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
	if (r != 0)//说明查到了
	{
		gtk_entry_set_text(GTK_ENTRY(yh_id),"已注册请登录");
		sqlite3_close(db);
		return;
	}
	// 如果是写就用sqlite3_exec
	// 如果还有操作就从获取数据开始
	char sql2[100] = "";
	errmsg = NULL;
	sprintf(sql2,"insert into user (xm,mm,ye,changguan) values(\'%s\',\'%s\',0,'无预约');",id,passwd);
	sqlite3_exec(db,sql2,NULL,NULL,&errmsg);
	if(errmsg!=NULL)
		printf("注册问题：%s\n",errmsg);
	// 如果没有就关闭数据库
	sqlite3_close(db);
	gtk_entry_set_text(GTK_ENTRY(yh_id),"已注册成功");

}

// 用户登录界面登录
void window_yh_dl(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(yh_passwd));
	const char * yzm = gtk_entry_get_text(GTK_ENTRY(yh_yzm));
	const char * yzm_old = gtk_label_get_text(GTK_LABEL(label_yh_yzms));
	if (0!=strcmp(yzm,yzm_old))//如果验证码错误
	{
		gtk_entry_set_text(GTK_ENTRY(yh_yzm),"验证码错误");
		sqlite3_close(db);
		return;
	}

	// 根据数据组合一个sql语句
	char sql1[100] = "";
	sprintf(sql1,"select *from user where xm = \'%s\' and mm = \'%s\';",id,passwd);
	// 看sql语句是读还是写
	char ** table = NULL;
	char * errmsg = NULL;
	int r = 0,c = 0;
	// 如果是读就用sqlite3_get_table
	sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
	if (r != 0)//说明查到了
	{
		//跳转
		gtk_widget_show_all(window_yh_cd);
		gtk_widget_hide_all(window_yh);
		printf("成功登录\n");
	}
	else
		gtk_entry_set_text(GTK_ENTRY(yh_id),"用户名或密码错误");
	sqlite3_close(db);
	return;
}

//用户充值
void yh_cz(GtkButton* button, gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	const char * yue = gtk_label_get_text(GTK_LABEL(yh_cz_yue));
	const char * jine = gtk_entry_get_text(GTK_ENTRY(yh_cz_jine));
	int new_yue =  atoi(yue) +atoi(jine);//atoi表示将字符串数字变int
	//组sql语句
	char sql[100] = "";
	char *errmsg = NULL;
	sprintf(sql,"update user set ye = %d where xm = \'%s\';",new_yue,id);
	sqlite3_exec(db,sql,NULL,NULL,&errmsg);
	sqlite3_close(db);
}

// 用户充值刷新
void yh_cz_sx(GtkButton* button,gpointer user_data)
{
	//按下充值按钮就先查询余额然后设置到label上再跳转
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	// 根据数据组合一个sql语句
	char sql1[100] = "";
	sprintf(sql1,"select ye from user where xm = \'%s\';",id);  //选择user表中yue那一列
	// 看sql语句是读还是写
	char ** table = NULL;
	char * errmsg = NULL;
	int r = 0,c = 0;
	// 如果是读就用sqlite3_get_table
	sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
	if(r!=0)//我们下面需要用到数据了所以先画图
	{
		//table[1]就是我们需要的数据,也就是余额
		//因此将table【1】设置到label上就完成了余额的显示
		gtk_label_set_text(GTK_LABEL(yh_cz_yue),table[1]);
		
	}
	sqlite3_close(db);
}


//用户查询信息函数
void yh_cd_to_yh_cx(GtkButton* button,gpointer user_data)
{

	const char * id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	sqlite3*db;
	sqlite3_open("qf.db",&db);
	char sql1[100] ="";
	sprintf(sql1,"select * from user where xm = \'%s\';",id);
	char **jg = NULL;
	int r = 0, c = 0;
	char *errmsg = NULL;
	sqlite3_get_table(db,sql1,&jg,&r,&c,&errmsg);
	if (r!=0)
	{
		
		gtk_label_set_text(GTK_LABEL(label_user_xm),jg[4]);
		gtk_label_set_text(GTK_LABEL(label_user_passwd),jg[5]);
		gtk_label_set_text(GTK_LABEL(label_user_ye),jg[7]);
		gtk_label_set_text(GTK_LABEL(label_user_changguan),jg[6]);
		
	}
	sqlite3_close(db);
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_yh_cx);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_yh_cd);
}

//管理员查询用户信息

void window_gly_cx_do_cx(GtkButton* button,gpointer user_data)
{

	const char * id = gtk_entry_get_text(GTK_ENTRY(gly_gly_cx_id));
	sqlite3*db;
	sqlite3_open("qf.db",&db);
	char sql1[100] ="";
	sprintf(sql1,"select * from user where xm = \'%s\';",id);
	char **jg = NULL;
	int r = 0, c = 0;
	char *errmsg = NULL;
	sqlite3_get_table(db,sql1,&jg,&r,&c,&errmsg);
	if (r!=0)
	{
		
		gtk_label_set_text(GTK_LABEL(gly_user_xm),jg[4]);
		gtk_label_set_text(GTK_LABEL(gly_user_passwd),jg[5]);
		gtk_label_set_text(GTK_LABEL(gly_user_ye),jg[7]);
		gtk_label_set_text(GTK_LABEL(gly_user_changguan),jg[6]);
		
	}
	sqlite3_close(db);
	//跳转就是显示下一个页面
	gtk_widget_show_all(window_gly_cx);  
	//隐藏当前的页面
	gtk_widget_hide_all(window_gly_cd);
}


//用户修改自己信息
void window_user_xg_do_user_xg(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);

	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(label_user_xg_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(label_user_xg_passwd));
    // 根据数据组合一个sql语句
	char sql1[100] = "";
	//sprintf(sql1,"update user set tel  = \'%s\'and passwd = \'%s\' where tel = \'%s\';",tel,passwd,(const char *)e_user_tel);
	sprintf(sql1,"update  user set mm = \'%s\' where xm = \'%s\';",passwd,id);
	

	// 看sql语句是读还是写
	char * errmsg = NULL;
	// 如果是写就用sqlite3_exec
	sqlite3_exec(db,sql1,NULL,NULL,&errmsg);
	if (errmsg!= NULL)//说明修改失败
	{
		printf("修改问题:%s\n",errmsg);
	 //如果没有就关闭数据库
	    sqlite3_close(db);
	    
		gtk_entry_set_text(GTK_ENTRY(label_user_xg_xm),"修改成功");
    }
}

//管理员修改用户信息
void window_gly_xg_do_gly_xg(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);

	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(gly_user_xg_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(gly_user_xg_passwd));
    // 根据数据组合一个sql语句
	char sql1[100] = "";
	//sprintf(sql1,"update user set tel  = \'%s\'and passwd = \'%s\' where tel = \'%s\';",tel,passwd,(const char *)e_user_tel);
	sprintf(sql1,"update  user set mm = \'%s\' where xm = \'%s\';",passwd,id);
	

	// 看sql语句是读还是写
	char * errmsg = NULL;
	// 如果是写就用sqlite3_exec
	sqlite3_exec(db,sql1,NULL,NULL,&errmsg);
	if (errmsg!= NULL)//说明修改失败
	{
		printf("修改问题:%s\n",errmsg);
	 //如果没有就关闭数据库
	    sqlite3_close(db);
	    
		gtk_entry_set_text(GTK_ENTRY(label_user_xg_xm),"修改成功");
    }
}

//用户预约函数、内有消费
void user_do_qryu(GtkButton* button,gpointer user_data)
{
	const char* id = gtk_entry_get_text(GTK_ENTRY(yh_id));
	const char* new = gtk_entry_get_text(GTK_ENTRY(entry_user_xzkcm));

	sqlite3* db;
	sqlite3_open("qf.db",&db);
	char sql4[100] ="";
	sprintf(sql4,"select ye from user where xm = \'%s\';",id);

	char **table2 = NULL;
	int r = 0, c = 0;
	char *errmsg = NULL;
	const char* mn;
	sqlite3_get_table(db,sql4,&table2,&r,&c,&errmsg);
	if (r!=0)
	{
		mn = table2[1];

    }
    if(atoi(mn)>=200)
	{
		char sql1[100] = "";
		sprintf(sql1,"select * from user where xm = \'%s\' and changguan = \'%s\';",id,new);

	char **table = NULL;
		int r =0,c =0;
		char *errmsg = NULL;
		sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
		if(r!=0)
		{
			gtk_entry_set_text(GTK_ENTRY(entry_user_xzkcm),"你已经选择过该场馆，请勿重复选择");


			return;
		}
		char sql2[100] = "";
		errmsg = NULL;
		sprintf(sql2,"update user set changguan = \'%s\' where xm= \'%s\';",new,id);
		sqlite3_exec(db,sql2,NULL,NULL,&errmsg);
		if(errmsg==NULL)
		{
			
			char sql3[100] = "";
			errmsg = NULL;
			sprintf(sql3,"update user set ye = ye-200 where xm= \'%s\';",id);
			sqlite3_exec(db,sql3,NULL,NULL,&errmsg);
			gtk_entry_set_text(GTK_ENTRY(entry_user_xzkcm),"选择成功");
		}
		else
			printf("%s\n", errmsg);

	}
	else
		gtk_entry_set_text(GTK_ENTRY(entry_user_xzkcm),"余额不足请先充值");



	
	sqlite3_close(db);
}

//管理员删除用户
void window_gly_sc_do_gly_sc(GtkButton* button,gpointer user_data)
{	
		const char* id = gtk_entry_get_text(GTK_ENTRY(label_gly_sc_id));
		sqlite3* db;
	sqlite3_open("qf.db",&db);
	char sql4[100] ="";
	sprintf(sql4,"delete from user where xm= \'%s\';",id);

	// 看sql语句是读还是写
	char * errmsg = NULL;
	// 如果是写就用sqlite3_exec
	sqlite3_exec(db,sql4,NULL,NULL,&errmsg);
	if (errmsg!= NULL)//说明修改失败
	{
		printf("删除问题:%s\n",errmsg);
	 //如果没有就关闭数据库
	    sqlite3_close(db);
	    
		gtk_entry_set_text(GTK_ENTRY(label_gly_sc_id),"删除成功");
    }
}


//管理员增加用户界面
void window_gly_zj_do_gly_zj(GtkButton* button,gpointer user_data)
{
	const char* id = gtk_entry_get_text(GTK_ENTRY(label_gly_zj_id));
	const char* passwd = gtk_entry_get_text(GTK_ENTRY(label_gly_zj_mm));

	sqlite3* db;
	sqlite3_open("qf.db",&db);
	char sql4[100] ="";
	sprintf(sql4,"insert into user (xm,mm,ye,changguan) values(\'%s\',\'%s\',0,'无预约');",id,passwd);

	// 看sql语句是读还是写
	char * errmsg = NULL;
	// 如果是写就用sqlite3_exec
	sqlite3_exec(db,sql4,NULL,NULL,&errmsg);
	if (errmsg!= NULL)//说明修改失败
	{
		printf("增加问题:%s\n",errmsg);
	 //如果没有就关闭数据库
	    sqlite3_close(db);
	    
		gtk_entry_set_text(GTK_ENTRY(label_gly_sc_id),"增加成功");
    }
}






//管理员登录界面刷新
void window_gly_do_sx(GtkButton* button,gpointer user_data)
{
	//清空界面
	gtk_entry_set_text(GTK_ENTRY(gly_id),"");
	gtk_entry_set_text(GTK_ENTRY(gly_passwd),"");
	gtk_entry_set_text(GTK_ENTRY(gly_yzm),"");
	//生成
	char haha[4] = "";
	srand(time(NULL));
	int i = 0;
	for (i = 0; i < 4; ++i)
	{
		if(rand()%2 == 0)
			haha[i] = rand()%26+'a';
		else
			haha[i] = rand()%10+'0';
	}

	//设置上去
	char yzm[200] = "";
	sprintf(yzm,"<span foreground='red'  font_desc='25'>%s</span>",haha);
	gtk_label_set_markup(GTK_LABEL(label_gly_yzms),yzm);
}


// 管理员注册
void window_gly_do_zc(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(gly_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(gly_passwd));
	const char * yzm = gtk_entry_get_text(GTK_ENTRY(gly_yzm));
	const char * yzm_old = gtk_label_get_text(GTK_LABEL(label_gly_yzms));
	if (0!=strcmp(yzm,yzm_old))//如果验证码错误
	{
		gtk_entry_set_text(GTK_ENTRY(gly_id),"验证码错误");
		sqlite3_close(db);
		return;
	}

	// 根据数据组合一个sql语句
	char sql1[100] = "";
	sprintf(sql1,"select * from gly where xm = \'%s\';",id);
	// 看sql语句是读还是写
	char ** table = NULL;
	char * errmsg = NULL;
	int r = 0,c = 0;
	// 如果是读就用sqlite3_get_table
	sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
	if (r != 0)//说明查到了
	{
		gtk_entry_set_text(GTK_ENTRY(gly_id),"已注册请登录");
		sqlite3_close(db);
		return;
	}
	// 如果是写就用sqlite3_exec
	// 如果还有操作就从获取数据开始
	char sql2[100] = "";
	errmsg = NULL;
	sprintf(sql2,"insert into gly  (xm,mm) values(\'%s\',\'%s\');",id,passwd);
	sqlite3_exec(db,sql2,NULL,NULL,&errmsg);
	if(errmsg!=NULL)
		printf("注册问题：%s\n",errmsg);
	// 如果没有就关闭数据库
	sqlite3_close(db);
	gtk_entry_set_text(GTK_ENTRY(gly_id),"已注册成功");
}


// 管理员登录
void window_gly_do_dl(GtkButton* button,gpointer user_data)
{
	// 打开数据库
	sqlite3 * db;
	sqlite3_open("qf.db",&db);
	// 获取需要操作的数据(获取输入框内容)
	const char * id = gtk_entry_get_text(GTK_ENTRY(gly_id));
	const char * passwd = gtk_entry_get_text(GTK_ENTRY(gly_passwd));
	const char * yzm = gtk_entry_get_text(GTK_ENTRY(gly_yzm));
	const char * yzm_old = gtk_label_get_text(GTK_LABEL(label_gly_yzms));
	if (0!=strcmp(yzm,yzm_old))//如果验证码错误
	{
		gtk_entry_set_text(GTK_ENTRY(gly_id),"验证码错误");
		sqlite3_close(db);
		return;
	}

	// 根据数据组合一个sql语句
	char sql1[100] = "";
	sprintf(sql1,"select *from gly where xm = \'%s\' and mm = \'%s\';",id,passwd);
	// 看sql语句是读还是写
	char ** table = NULL;
	char * errmsg = NULL;
	int r = 0,c = 0;
	// 如果是读就用sqlite3_get_table
	sqlite3_get_table(db,sql1,&table,&r,&c,&errmsg);
	if (r != 0)//说明查到了
	{
		//跳转
		gtk_widget_show_all(window_gly_cd);
		gtk_widget_hide_all(window_gly);
		printf("登录成功\n");
	}
	else
		gtk_entry_set_text(GTK_ENTRY(gly_id),"用户名或密码错误");
	sqlite3_close(db);
	return;
}



//----------------------------------------------

//--------------优化区域--------------------------
// 修改字体大小
static void set_widget_font_size(GtkWidget *widget, int size, gboolean is_button)
{
	GtkWidget *labelChild;  
	PangoFontDescription *font;  
	gint fontSize = size;  
 
	font = pango_font_description_from_string("Sans");          //"Sans"字体名   
	pango_font_description_set_size(font, fontSize*PANGO_SCALE);//设置字体大小   
 
	if(is_button){
		labelChild = gtk_bin_get_child(GTK_BIN(widget));//取出GtkButton里的label  
	}else{
		labelChild = widget;
	}
 
	//设置label的字体，这样这个GtkButton上面显示的字体就变了
	gtk_widget_modify_font(GTK_WIDGET(labelChild), font);
	pango_font_description_free(font);
}
//   label   set_widget_font_size(label, 50, FALSE);			// 设置标签字体大小
//  button	 set_widget_font_size(button, 50, TRUE);
// 背景图片设置
void chang_background(GtkWidget *widget, int w, int h, const gchar *path)
{
	gtk_widget_set_app_paintable(widget, TRUE);		//允许窗口可以绘图
	gtk_widget_realize(widget);	
 
	/* 更改背景图时，图片会重叠
	 * 这时要手动调用下面的函数，让窗口绘图区域失效，产生窗口重绘制事件（即 expose 事件）。
	 */
	gtk_widget_queue_draw(widget);
 
	GdkPixbuf *src_pixbuf = gdk_pixbuf_new_from_file(path, NULL);	// 创建图片资源对象
	// w, h是指定图片的宽度和高度
	GdkPixbuf *dst_pixbuf = gdk_pixbuf_scale_simple(src_pixbuf, w, h, GDK_INTERP_BILINEAR);
 
	GdkPixmap *pixmap = NULL;
 
	/* 创建pixmap图像; 
	 * NULL：不需要蒙版; 
	 * 123： 0~255，透明到不透明
	 */
	gdk_pixbuf_render_pixmap_and_mask(dst_pixbuf, &pixmap, NULL, 128);
	// 通过pixmap给widget设置一张背景图，最后一个参数必须为: FASLE
	gdk_window_set_back_pixmap(widget->window, pixmap, FALSE);
 
	// 释放资源
	g_object_unref(src_pixbuf);
	g_object_unref(dst_pixbuf);
	g_object_unref(pixmap);
}
//---------------------------------------------------



//-------------------窗口界面函数-----------------------


//------------刚开始的主界面，系统开始窗口---------------
void window_main_init(void)
{
	window_main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_main,1024,724);
	chang_background(window_main,1024,724,"./1.jpg");
	GtkWidget* vbox = gtk_vbox_new(TRUE,10);
	gtk_container_add(GTK_CONTAINER(window_main),vbox);
	GtkWidget* label = gtk_label_new("欢迎进入zzuli体育馆管理系统");
	gtk_container_add(GTK_CONTAINER(vbox),label);
	set_widget_font_size(label, 50, FALSE);
	GtkWidget* button = gtk_button_new_with_label("进入");
	gtk_container_add(GTK_CONTAINER(vbox),button);
	set_widget_font_size(button, 29, TRUE);
	
	g_signal_connect(button, "pressed",G_CALLBACK(window_main_to_rk),NULL);
    //window_main_to_rk是值跳转到主函数到入口界面函数
}

//----------------入口界面--------------
void window_rk_init(void)
{
	window_rk = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_rk,500,300);
	chang_background(window_rk,500,300,"./3.jpg");
	GtkWidget* table = gtk_table_new(3,2,TRUE);
	gtk_container_add(GTK_CONTAINER(window_rk),table);
	GtkWidget* label_title = gtk_label_new("体育馆管理系统入口");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='blue' font_desc='18'>体育馆管理系统入口</span>");
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,2,0,1);
	GtkWidget* button_yh = gtk_button_new_with_label("用户");
	gtk_table_attach_defaults(GTK_TABLE(table),button_yh,0,1,2,3);
	GtkWidget* button_gly = gtk_button_new_with_label("管理员");
	gtk_table_attach_defaults(GTK_TABLE(table),button_gly,1,2,2,3);

	g_signal_connect(button_yh,"pressed",G_CALLBACK(window_rk_to_yh),NULL); 
	//window_rk_to_yh 进入用户界面
	g_signal_connect(button_gly,"pressed",G_CALLBACK(window_rk_to_gly),NULL);
	//window_rk_to_gly进入管理员界面
}

//----------------用户登录界面--------------------
void window_yh_init(void)
{
	window_yh = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//gtk 控件 指针    gtk   窗口 新建  窗口属性：置顶有边框
	//设置窗口的属性
	gtk_widget_set_size_request(window_yh,780,456);
	chang_background(window_yh,780,456,"./2.jpg");
	//切记要把图片放当前的文件夹中并且命名为2.jpg
	gtk_window_set_title(GTK_WINDOW(window_yh),"用户");
	GtkWidget* table = gtk_table_new(5,4,TRUE);//创建一个均匀的5*4的表格布局
	//将table放入窗口
	gtk_container_add(GTK_CONTAINER(window_yh),table);
	//创建其他的控件并放入
	GtkWidget* label_title  = gtk_label_new("欢迎来到用户端");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='blue'  font_desc='28'>欢迎来到用户端</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,4,0,1);
	
	//创建其他的控件并放入
	GtkWidget* label_id  = gtk_label_new("账号：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_id),"<span foreground='blue'  font_desc='25'>账号：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_id,0,1,1,2);
	//创建其他的控件并放入
	GtkWidget* label_passwd  = gtk_label_new("密码：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_passwd),"<span foreground='blue'  font_desc='25'>密码：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,2,3);
	//创建其他的控件并放入
	GtkWidget* label_yzm  = gtk_label_new("验证码：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_yzm),"<span foreground='blue'  font_desc='25'>验证码：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_yzm,0,1,3,4);
	
	//创建三个--------------------------行编辑
	yh_id = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),yh_id,1,3,1,2);
	yh_passwd = gtk_entry_new();
	gtk_entry_set_visibility(GTK_ENTRY(yh_passwd),FALSE);//设置为密码模式
	gtk_table_attach_defaults(GTK_TABLE(table),yh_passwd,1,3,2,3);
	yh_yzm = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),yh_yzm,1,3,3,4);
	
	//创建验证码并且生成一个初始的验证码设置上去
	label_yh_yzms = gtk_label_new("");

	char haha[4] = "";
	srand(time(NULL));
	int i = 0;
	for (i = 0; i < 4; ++i)
	{
		if(rand()%2 == 0)
			haha[i] = rand()%26+'a';
		else
			haha[i] = rand()%10+'0';
	}

	gtk_label_set_text(GTK_LABEL(label_yh_yzms),haha);
	char yzm[200] = "";
	sprintf(yzm,"<span foreground='red'  font_desc='25'>%s</span>",haha);
	gtk_label_set_markup(GTK_LABEL(label_yh_yzms),yzm);
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_yh_yzms,3,4,3,4);
	
	GtkWidget* button_dl = gtk_button_new_with_label("登录");
	gtk_table_attach_defaults(GTK_TABLE(table),button_dl,0,1,4,5);
	
	GtkWidget* button_zc = gtk_button_new_with_label("注册");
	gtk_table_attach_defaults(GTK_TABLE(table),button_zc,1,2,4,5);
	
	GtkWidget* button_sx = gtk_button_new_with_label("刷新");
	gtk_table_attach_defaults(GTK_TABLE(table),button_sx,2,3,4,5);
	
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,4,5);
	
	g_signal_connect(button_sx,"pressed",G_CALLBACK(window_yh_sx),NULL); // window_yh_sx 用户进入刷新界面
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_yh_to_rk),NULL);  // window_yh_to_rk 用户返回入口界面
	g_signal_connect(button_zc,"pressed",G_CALLBACK(window_yh_zc),NULL);  //window_yh_zc  用户进入注册界面
	g_signal_connect(button_dl,"pressed",G_CALLBACK(window_yh_dl),NULL);  //window_yh_dl  用户进入登录界面

}

//用户功能菜单界面
void window_yh_cd_init(void)
{
	window_yh_cd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_yh_cd,780,456);
	chang_background(window_yh_cd,780,456,"./4.jpg");
	GtkWidget* table = gtk_table_new(3,3,TRUE);
	gtk_container_add(GTK_CONTAINER(window_yh_cd),table);
	GtkWidget* label_title = gtk_label_new("用户功能菜单");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='grey' font_desc='28'>用户功能菜单</span>");
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,1,2,0,1);
	GtkWidget* button_cz = gtk_button_new_with_label("充值");
	gtk_table_attach_defaults(GTK_TABLE(table),button_cz,0,1,1,2);
	gtk_button_set_relief(GTK_BUTTON(button_cz),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_cx = gtk_button_new_with_label("查看个人所有信息");
	gtk_table_attach_defaults(GTK_TABLE(table),button_cx,1,2,1,2);
	gtk_button_set_relief(GTK_BUTTON(button_cx),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_xg = gtk_button_new_with_label("修改自己信息");
	gtk_table_attach_defaults(GTK_TABLE(table),button_xg,2,3,1,2);
	gtk_button_set_relief(GTK_BUTTON(button_xg),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_yu = gtk_button_new_with_label("预约");
	gtk_table_attach_defaults(GTK_TABLE(table),button_yu,0,3,2,3);
	gtk_button_set_relief(GTK_BUTTON(button_yu),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,2,3,0,1);
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明

	g_signal_connect(button_cz,"pressed",G_CALLBACK(yh_cd_to_yh_cz),NULL);
	g_signal_connect(button_cx,"pressed",G_CALLBACK(yh_cd_to_yh_cx),NULL);
	g_signal_connect(button_fh,"pressed",G_CALLBACK(yh_cd_to_yh_dl),NULL);
	g_signal_connect(button_xg,"pressed",G_CALLBACK(yh_cd_to_yh_xg),NULL);
	g_signal_connect(button_yu,"pressed",G_CALLBACK(yh_cd_to_yh_yu),NULL);
}


//用户充值界面
void window_yh_cz_init(void)
{
	window_yh_cz = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_yh_cz,958,539);
	chang_background(window_yh_cz,958,539,"./2.png");
	GtkWidget* table = gtk_table_new(4,3,TRUE);
	gtk_container_add(GTK_CONTAINER(window_yh_cz),table);
	GtkWidget* label_title = gtk_label_new("用户充值");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='red'  font_desc='28'>用户充值</span>");
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,3,0,1);

	GtkWidget* label_yue = gtk_label_new("余额");
	gtk_label_set_markup(GTK_LABEL(label_yue),"<span foreground='red'  font_desc='22'>余额：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_yue,0,1,1,2);
	GtkWidget* label_jine = gtk_label_new("金额");
	gtk_label_set_markup(GTK_LABEL(label_jine),"<span foreground='red'  font_desc='22'>金额：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_jine,0,1,2,3);
	yh_cz_yue = gtk_label_new("");
	gtk_label_set_markup(GTK_LABEL(yh_cz_yue),"<span foreground='red'  font_desc='22'></span>");
	gtk_table_attach_defaults(GTK_TABLE(table),yh_cz_yue,1,2,1,2);
	yh_cz_jine = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),yh_cz_jine,1,2,2,3);
	
	GtkWidget* button_cz = gtk_button_new_with_label("充值");
	gtk_table_attach_defaults(GTK_TABLE(table),button_cz,0,1,3,4);
	GtkWidget* button_sx = gtk_button_new_with_label("刷新");
	gtk_table_attach_defaults(GTK_TABLE(table),button_sx,1,2,3,4);
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,2,3,3,4);

	g_signal_connect(button_cz,"pressed",G_CALLBACK(yh_cz),NULL);
	g_signal_connect(button_sx,"pressed",G_CALLBACK(yh_cz_sx),NULL);
	g_signal_connect(button_fh,"pressed",G_CALLBACK(yh_cz_to_cd),NULL);
}


//用户查询信息界面
void window_yh_cx_init(void)
{
	window_yh_cx = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_yh_cx,958,539);
	chang_background(window_yh_cx, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(3,4,TRUE);
	gtk_container_add(GTK_CONTAINER(window_yh_cx),table);
	GtkWidget* label_title = gtk_label_new("个人信息");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,3,0,1);


	GtkWidget* label_xm = gtk_label_new("姓名：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_xm,0,1,1,2);
	GtkWidget* label_changguan = gtk_label_new("场馆：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_changguan,2,3,1,2);
	GtkWidget* label_passwd = gtk_label_new("密码：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,2,3);
	GtkWidget* label_ye = gtk_label_new("余额：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_ye,2,3,2,3);

	label_user_xm=gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xm,1,2,1,2);
	label_user_passwd = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_passwd,1,2,2,3);
	label_user_changguan = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_changguan,3,4,1,2);
	label_user_ye = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_ye,3,4,2,3);
	
	
	
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,0,1);
	
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_cx_to_cd),NULL);
	
}

//管理员查询用户信息界面
void window_gly_cx_init(void)
{
	window_gly_cx = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_gly_cx,958,539);
	chang_background(window_gly_cx, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(4,4,TRUE);
	gtk_container_add(GTK_CONTAINER(window_gly_cx),table);
	GtkWidget* label_title = gtk_label_new("用户信息");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,3,0,1);


	GtkWidget* label_xm = gtk_label_new("姓名：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_xm,0,1,1,2);
	GtkWidget* label_changguan = gtk_label_new("场馆：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_changguan,2,3,1,2);
	GtkWidget* label_passwd = gtk_label_new("密码：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,2,3);
	GtkWidget* label_ye = gtk_label_new("余额：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_ye,2,3,2,3);
	GtkWidget* label_shuru = gtk_label_new("请输入你要查询的用户姓名：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_shuru,0,3,3,4);

	gly_user_xm=gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_xm,1,2,1,2);
	gly_user_passwd = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_passwd,1,2,2,3);
	gly_user_changguan = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_changguan,3,4,1,2);
	gly_user_ye = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_ye,3,4,2,3);

	gly_gly_cx_id=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_gly_cx_id,3,4,3,4);//请输入你要查询的用户姓名
	
	
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,0,1);

	GtkWidget* button_qrcx = gtk_button_new_with_label("确认");
	gtk_button_set_relief(GTK_BUTTON(button_qrcx),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_qrcx,0,1,0,1);



	g_signal_connect(button_qrcx,"pressed",G_CALLBACK(window_gly_cx_do_cx),NULL);
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_gly_cx_to_cd),NULL);
}


//用户修改信息界面
 void window_user_xg_init(void)
{
	window_yh_xg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_yh_xg,958,539);
	chang_background(window_yh_xg, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(5,4,TRUE);
	gtk_container_add(GTK_CONTAINER(window_yh_xg),table);
	GtkWidget* label_title = gtk_label_new("个人信息修改");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,1,3,0,1);


    GtkWidget* label_user_xm = gtk_label_new("要修改的账号id:");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xm,0,1,1,2);
	GtkWidget* label_passwd = gtk_label_new("密码修改为：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,3,4);

	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,0,1);
	
	GtkWidget* button_qrxg = gtk_button_new_with_label("确认修改");
	gtk_button_set_relief(GTK_BUTTON(button_qrxg),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_qrxg,1,3,4,5);
	

	label_user_xg_id=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xg_id,1,3,1,2);
	label_user_xg_xm = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xg_xm,1,3,2,3);
	label_user_xg_passwd = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xg_passwd,1,3,3,4);
	
	
	

	
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_xg_to_cd),NULL);
	g_signal_connect(button_qrxg,"pressed",G_CALLBACK(window_user_xg_do_user_xg),NULL);
	
}

//管理员修改用户信息界面
void window_gly_xg_init(void)
{
	window_gly_xg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_gly_xg,958,539);
	chang_background(window_gly_xg, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(5,4,TRUE);
	gtk_container_add(GTK_CONTAINER(window_gly_xg),table);
	GtkWidget* label_title = gtk_label_new("用户信息修改");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,1,3,0,1);


    GtkWidget* label_user_xm = gtk_label_new("要修改的账号id:");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xm,0,1,1,2);
	GtkWidget* label_passwd = gtk_label_new("密码修改为：");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,3,4);

	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,0,1);
	
	GtkWidget* button_qrxg = gtk_button_new_with_label("确认修改");
	gtk_button_set_relief(GTK_BUTTON(button_qrxg),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_qrxg,1,3,4,5);
	

	gly_user_xg_id=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_xg_id,1,3,1,2);
	gly_user_xg_xm = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_xg_xm,1,3,2,3);
	gly_user_xg_passwd = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_user_xg_passwd,1,3,3,4);
	
	
	

	
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_gly_xg_to_gly_cd),NULL);
	g_signal_connect(button_qrxg,"pressed",G_CALLBACK(window_gly_xg_do_gly_xg),NULL);
}

//用户预约界面
void window_user_yu_init(void)
{
	window_yh_yu = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_yh_yu,958,539);
	chang_background(window_yh_yu, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(3,3,TRUE);
    gtk_container_add(GTK_CONTAINER(window_yh_yu),table);
    GtkWidget* label_title = gtk_label_new("请选择你的场馆");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,1,2,0,1);

    GtkWidget* button_1 = gtk_button_new_with_label("第一场馆");
	gtk_table_attach_defaults(GTK_TABLE(table),button_1,0,1,1,2);
	GtkWidget* button_2 = gtk_button_new_with_label("第二场馆");
	gtk_table_attach_defaults(GTK_TABLE(table),button_2,1,2,1,2);
	GtkWidget* button_3 = gtk_button_new_with_label("第三场馆");
	gtk_table_attach_defaults(GTK_TABLE(table),button_3,0,1,2,3);
	GtkWidget* button_4 = gtk_button_new_with_label("第四场馆");
	gtk_table_attach_defaults(GTK_TABLE(table),button_4,1,2,2,3);

	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,2,3,0,1);
    GtkWidget* button_qr = gtk_button_new_with_label("确认");
	gtk_table_attach_defaults(GTK_TABLE(table),button_qr,2,3,2,3);

	entry_user_xzkcm = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),entry_user_xzkcm,2,3,1,2);	

    g_signal_connect(button_fh,"pressed",G_CALLBACK(window_yu_to_cd),NULL);
    g_signal_connect(button_1,"pressed",G_CALLBACK(user_do_yu),NULL);
    g_signal_connect(button_2,"pressed",G_CALLBACK(user_do_yu),NULL);
    g_signal_connect(button_3,"pressed",G_CALLBACK(user_do_yu),NULL);
    g_signal_connect(button_4,"pressed",G_CALLBACK(user_do_yu),NULL);
    g_signal_connect(button_qr,"pressed",G_CALLBACK(user_do_qryu),NULL);
}


//管理员登录界面
void window_gly_init()
{
	window_gly = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//gtk 控件 指针    gtk   窗口 新建  窗口属性：置顶有边框
	//设置窗口的属性
	gtk_widget_set_size_request(window_gly,780,456);
	chang_background(window_gly,780,456,"./2.jpg");
	gtk_window_set_title(GTK_WINDOW(window_gly),"管理员");
	GtkWidget* table = gtk_table_new(5,4,TRUE);//创建一个均匀的5*4的表格布局
	//将table放入窗口
	gtk_container_add(GTK_CONTAINER(window_gly),table);
	//创建其他的控件并放入
	GtkWidget* label_title  = gtk_label_new("欢迎来到管理员端");
	gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='red' font_desc='28'>欢迎来到管理员端</span>");
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,4,0,1);
	
	//创建其他的控件并放入
	GtkWidget* label_id  = gtk_label_new("账号：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_id),"<span foreground='red'  font_desc='25'>账号：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_id,0,1,1,2);
	//创建其他的控件并放入
	GtkWidget* label_passwd  = gtk_label_new("密码：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_passwd),"<span foreground='red'  font_desc='25'>密码：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_passwd,0,1,2,3);
	//创建其他的控件并放入
	GtkWidget* label_yzm  = gtk_label_new("验证码：");
	//设置label的颜色大小
	gtk_label_set_markup(GTK_LABEL(label_yzm),"<span foreground='red'  font_desc='25'>验证码：</span>");
	gtk_table_attach_defaults(GTK_TABLE(table),label_yzm,0,1,3,4);
	
	//创建三个--------------------------行编辑
	gly_id = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_id,1,3,1,2);
	gly_passwd = gtk_entry_new();
	gtk_entry_set_visibility(GTK_ENTRY(gly_passwd),FALSE);//设置为密码模式
	gtk_table_attach_defaults(GTK_TABLE(table),gly_passwd,1,3,2,3);
	gly_yzm = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),gly_yzm,1,3,3,4);
	
	//创建验证码并且生成一个初始的验证码设置上去
	label_gly_yzms = gtk_label_new("");

	char haha[4] = "";
	srand(time(NULL));
	int i = 0;
	for (i = 0; i < 4; ++i)
	{
		if(rand()%2 == 0)
			haha[i] = rand()%26+'a';
		else
			haha[i] = rand()%10+'0';
	}

	gtk_label_set_text(GTK_LABEL(label_gly_yzms),haha);
	char yzm[200] = "";
	sprintf(yzm,"<span foreground='red'  font_desc='25'>%s</span>",haha);
	gtk_label_set_markup(GTK_LABEL(label_gly_yzms),yzm);
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_gly_yzms,3,4,3,4);
	
	GtkWidget* button_dl = gtk_button_new_with_label("登录");
	gtk_table_attach_defaults(GTK_TABLE(table),button_dl,0,1,4,5);
	
	GtkWidget* button_zc = gtk_button_new_with_label("注册");
	gtk_table_attach_defaults(GTK_TABLE(table),button_zc,1,2,4,5);
	
	GtkWidget* button_sx = gtk_button_new_with_label("刷新");
	gtk_table_attach_defaults(GTK_TABLE(table),button_sx,2,3,4,5);
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,3,4,4,5);
	
	g_signal_connect(button_sx,"pressed",G_CALLBACK(window_gly_do_sx),NULL);
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_gly_to_rk),NULL);
	g_signal_connect(button_zc,"pressed",G_CALLBACK(window_gly_do_zc),NULL);
	g_signal_connect(button_dl,"pressed",G_CALLBACK(window_gly_do_dl),NULL);

}

//管理员菜单界面
void window_gly_cd_init(void)
{
	window_gly_cd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_gly_cd,780,456);
	chang_background(window_gly_cd,780,456,"./4.jpg");
	GtkWidget* table = gtk_table_new(3,2,TRUE);
	gtk_container_add(GTK_CONTAINER(window_gly_cd),table);
	GtkWidget* label_title = gtk_label_new("管理员功能菜单");
gtk_label_set_markup(GTK_LABEL(label_title),"<span foreground='red' font_desc='28'>管理员功能菜单</span>");
	
	
	gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,2,0,1);

	GtkWidget* button_cx = gtk_button_new_with_label("查询用户");
	gtk_table_attach_defaults(GTK_TABLE(table),button_cx,0,1,1,2);
gtk_button_set_relief(GTK_BUTTON(button_cx),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_zj = gtk_button_new_with_label("增加用户");
	gtk_table_attach_defaults(GTK_TABLE(table),button_zj,1,2,1,2);
gtk_button_set_relief(GTK_BUTTON(button_zj),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_sc = gtk_button_new_with_label("删除用户");
	gtk_table_attach_defaults(GTK_TABLE(table),button_sc,0,1,2,3);
gtk_button_set_relief(GTK_BUTTON(button_sc),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_xg = gtk_button_new_with_label("修改用户");
	gtk_table_attach_defaults(GTK_TABLE(table),button_xg,1,2,2,3);
gtk_button_set_relief(GTK_BUTTON(button_xg),GTK_RELIEF_NONE);	// 按钮背景色透明
	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,1,2,0,1);
gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明


	g_signal_connect(button_cx,"pressed",G_CALLBACK(gly_cd_to_gly_cx),NULL);
	g_signal_connect(button_zj,"pressed",G_CALLBACK(gly_cd_to_gly_zj),NULL);
	g_signal_connect(button_sc,"pressed",G_CALLBACK(gly_cd_to_gly_sc),NULL);
	g_signal_connect(button_xg,"pressed",G_CALLBACK(gly_cd_to_gly_xg),NULL);
    g_signal_connect(button_fh,"pressed",G_CALLBACK(gly_cd_to_gly),NULL);
}


//管理员删除用户界面
void window_gly_sc_init(void)
{
    window_gly_sc = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_gly_sc,958,539);
	chang_background(window_gly_sc, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(3,3,TRUE);
	gtk_container_add(GTK_CONTAINER(window_gly_sc),table);
	GtkWidget* label_title = gtk_label_new("删除用户界面");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,3,0,1);


    GtkWidget* label_user_xm = gtk_label_new("要删除的账号id:");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xm,0,2,1,2);
	

	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,2,3,0,1);
	
	GtkWidget* button_qrsc = gtk_button_new_with_label("确认删除");
	gtk_button_set_relief(GTK_BUTTON(button_qrsc),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_qrsc,1,2,2,3);
	

	label_gly_sc_id=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_gly_sc_id,2,3,1,2);

	
	
	

	
	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_gly_sc_to_gly_cd),NULL);
	g_signal_connect(button_qrsc,"pressed",G_CALLBACK(window_gly_sc_do_gly_sc),NULL);

}

//管理员增加用户界面
 void window_gly_zj_init(void)
 {
 	window_gly_zj = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request(window_gly_zj,958,539);
	chang_background(window_gly_zj, 958,539,"./2.png");	// 设置窗口背景图
	GtkWidget* table = gtk_table_new(4,3,TRUE);
	gtk_container_add(GTK_CONTAINER(window_gly_zj),table);
	GtkWidget* label_title = gtk_label_new("增加用户界面");
    gtk_table_attach_defaults(GTK_TABLE(table),label_title,0,3,0,1);


    GtkWidget* label_user_xm = gtk_label_new("要增加的账号id:");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_xm,0,2,1,2);
	GtkWidget* label_user_mm = gtk_label_new("要增加的账号密码:");
	gtk_table_attach_defaults(GTK_TABLE(table),label_user_mm,0,2,2,3);

	GtkWidget* button_fh = gtk_button_new_with_label("返回");
	gtk_button_set_relief(GTK_BUTTON(button_fh),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_fh,2,3,0,1);
	
	GtkWidget* button_qrzj = gtk_button_new_with_label("确认增加");
	gtk_button_set_relief(GTK_BUTTON(button_qrzj),GTK_RELIEF_NONE);	// 按钮背景色透明
	gtk_table_attach_defaults(GTK_TABLE(table),button_qrzj,1,2,3,4);

	label_gly_zj_id=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_gly_zj_id,2,3,1,2);
	label_gly_zj_mm=gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table),label_gly_zj_mm,2,3,2,3);

	g_signal_connect(button_fh,"pressed",G_CALLBACK(window_gly_zj_to_gly_cd),NULL);
	g_signal_connect(button_qrzj,"pressed",G_CALLBACK(window_gly_zj_do_gly_zj),NULL);



	
 }




//--------------------------------------------------------------------




//----------------------数据库初始化--------------------------
//用户表中依次有姓名，身份证，密码，场馆，余额，电话，座位
//char *sql = "create table user (xm text,sfz text,mm text, changguan text,ye int,dh text,zw text);";
//创建管理员表格中有姓名，密码
//char *sql2 ="create table ds (xm text,mm text);";
void my_sql_init(void)//数据库初始化
{
	//创建句柄-想自己要做什么-组sql语句-打开数据库-发sql语句-关闭
	sqlite3* db;
	//用户表中依次有姓名，密码，场馆，余额
	char *sql = "create table user (xm text,mm text, changguan text,ye int);";
	sqlite3_open("qf.db",&db);
	char * errmsg = NULL;
	sqlite3_exec(db,sql,NULL,NULL,&errmsg);
	//创建管理员表格中有姓名，密码
	char *sql2 ="create table gly (xm text,mm text);";
	errmsg = NULL;
	sqlite3_exec(db,sql2,NULL,NULL,&errmsg);
	sqlite3_close(db);
}
//------------------------------------------------------------































//------------main函数区-------
int main(int argc, char *argv[])
{
	
	my_sql_init();
	gtk_init(&argc,&argv);
	//初始化主窗口
	window_main_init(); //进入主界面
	window_rk_init();  // 进入入口界面
    window_yh_init(); //用户登录界面
    window_yh_cd_init(); //用户功能菜单界面
    window_yh_cz_init(); //用户充值界面
    window_yh_cx_init(); //用户查询信息界面
    window_user_xg_init();//用户修改信息界面 
    window_user_yu_init();//用户预约场馆界面


    //管理员
    window_gly_init(); //管理员登录界面
    window_gly_cd_init();//管理员菜单界面
    window_gly_cx_init();//管理员查询用户界面
    window_gly_xg_init();//管理员修改用户密码界面
	window_gly_sc_init();//管理员删除用户界面
	window_gly_zj_init();//管理员增加用户界面

	//界面初始化
	g_signal_connect(window_main,"destroy",G_CALLBACK(gtk_main_quit),NULL);
	gtk_widget_show_all(window_main);
	gtk_main();
	return 0;
}

//---------------------------------